//
//  MineVC.m
//  HappyRent
//
//  Created by CoderYee on 2017/3/28.
//  Copyright © 2017年 内圈科技. All rights reserved.
//

#import "MineVC.h"
#import "EditMineVC.h"      //编辑个人中心
#import "SetVC.h"           //设置
#import "OrderVC.h"         //订单
#import "TabBarVC.h"
#import "YeeLoginVC.h"      //登录VC
#import "HelpVC.h"          //帮助VC
#import "MineHeaderView.h"
#import "MineFootView.h"
@interface MineVC ()

@end

@implementation MineVC

-(void)configOwnViews{
    
    [super configOwnViews];
    [self.view setBackgroundColor:[UIColor clearColor]];
    self.tableView.separatorColor=kNavBarThemeColor;
    self.tableView.frame = CGRectMake(0, 0, kMainScreenWidth*0.70, kMainScreenHeight-44);
}
-(void)addOwnViews{
    
    [self addCoverView];
    
    [super addOwnViews];
    
    [self addHeaderView];
    
    [self addtableFootView];
    
}
-(void)addHeaderView{
    
    MineHeaderView *headerView=[[MineHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, self.tableView.frame.size.width*0.5)];
    @weakify(self);
    [headerView.clickSubject subscribeNext:^(id  _Nullable x) {
      
        @strongify(self);
        EditMineVC  *mine=[EditMineVC new];
        mine.hidesBottomBarWhenPushed=YES;
        TabBarVC *tab= (TabBarVC*)self.tabBarController;
        [tab hideRightVCcompletion:^(BOOL finished) {
        [self.tabBarController.selectedViewController   pushViewController: mine animated:YES];
        }];
       
    }];
    self.tableView.tableHeaderView=headerView;
}
//添加切换商家
-(void)addtableFootView{
  
    MineFootView *footView=[[MineFootView alloc] initWithFrame:CGRectMake(0,kMainScreenHeight-44, self.tableView.frame.size.width,44)];
    [footView setBackgroundColor:kWhiteColor];
    
    footView.clickBlock=^(UIView *view){
        
        [[AppDelegate sharedAppDelegate]  enterSellerUI];
    };
    [self.view addSubview:footView];
    
}
-(void)addCoverView{

    UIButton *cover=[UIButton buttonWithType:UIButtonTypeCustom];
    cover.frame=self.view.frame;
    [self.view addSubview:cover];
    @weakify(self);
    [[cover rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        TabBarVC *tab= (TabBarVC*)self.tabBarController;
        [tab hideRightVCcompletion:^(BOOL finished) {
            
        }];
    }];
}
-(void)registerCellClass{
    
    [super registerCellClass];
    
}
#pragma mark  UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 7;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    BaseTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:[BaseTableViewCell cellIdentifier] forIndexPath:indexPath];
    NSArray  *titleArray=@[@"设置",@"钱包",@"我的订单",@"我的优惠券",@"实名认证",@"邀请好友",@"帮助"];
    NSArray *imageArray=@[@"tabbar_mall",@"tabbar_mall",@"tabbar_setting",@"tabbar_mall",@"tabbar_setting",@"tabbar_mall",@"tabbar_setting"];
    cell.textLabel.textColor=kBlackColor;
    cell.textLabel.font=[UIFont systemFontOfSize:14];
    cell.textLabel.text=titleArray[indexPath.row];
    cell.imageView.image=[[UIImage imageNamed:imageArray[indexPath.row] ] imageWithGradientTintColor:kNavBarThemeColor];
    return cell;
}
#pragma mark  点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *VcArray=@[@"SetVC",@"RedVC",@"OrderVC",@"CouponVC",@"AuthenticationVC",@"EditMineVC",@"HelpVC",];
    Class vcClass = NSClassFromString(VcArray[indexPath.row]);
    UIViewController *vc = [[vcClass alloc] init];
    vc.hidesBottomBarWhenPushed=YES;
    TabBarVC *tab= (TabBarVC*)self.tabBarController;
    [tab hideRightVCcompletion:^(BOOL finished) {
        
//        YeeLoginVC  *loginVc=[[YeeLoginVC alloc] init];
//        UINavigationController  *nav=[[UINavigationController alloc] initWithRootViewController:loginVc];
//        [self.tabBarController.selectedViewController  presentViewController:nav animated:YES completion:^{
//            
//        }];
        
    [self.tabBarController.selectedViewController  pushViewController:vc animated:YES];
    }];
}
//cell顶格
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]){
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
}
@end
